<?php

/**
 * FileName: InfoController.php
 * Author: @163.com
 * DateTime: 2023-02-21 下午 09:54
 * Summary:
 */


namespace App\Http\Controllers\Api\User;


use App\Http\Controllers\Api\BasicController;
use App\Models\SiteCode;
use App\Models\User;
use App\Models\UserFocus;
use App\Models\UserInfo;
use App\Models\Users\UsersFeedback;
use App\Services\Sms;
use GatewayWorker\Lib\Gateway;
use Jiannei\Response\Laravel\Support\Facades\Response;
use Tencent\TLSSigAPIv2;

class UserController extends BasicController
{



    /**
     * @api {post} /user/focus 关注用户
     * @apiName UserInfoLocation
     * @apiGroup UserInfo
     * @apiDescription
     * @apiHeader {String} Authorization='Bearer '
     */
    public function focus()
    {
        $focus_id=$this->request->input('focus_id');
        $is_focus=$this->request->input('is_focus',1);
        $user=User::find($focus_id);

        if($is_focus ==0 ){
            UserFocus::where(['user_id'=>$this->uid(),'focus_id'=>$focus_id])->delete();
            $result['is_focus']=User::getFocusStatus($this->uid(),$focus_id);
            return Response::success($result);
        }
        if($user && $is_focus==1){
            $result=UserFocus::create(['user_id'=>$this->uid(),'focus_id'=>$focus_id]);
            $result['is_focus']=User::getFocusStatus($this->uid(),$focus_id);
            return Response::success($result);
        }
        return Response::fail('关注用户不存在');
    }

    /**
     * @api {post} /user/my-fans 我的粉丝
     * @apiName UserInfoLocation
     * @apiGroup UserInfo
     * @apiDescription
     * @apiHeader {String} Authorization='Bearer '
     */

    public function myFans(){
        $type = $this->request->input('type',1);
        $uid = $this->request->input('uid',$this->uid());
        $result=(new User())->getFans($uid,$type);
        return Response::success($result);

    }

    /**
     * @api {post} /user/my-focus 我的关注
     * @apiName UserInfoLocation
     * @apiGroup UserInfo
     * @apiDescription
     * @apiHeader {String} Authorization='Bearer '
     */

    public function myFocus(){
        $type = $this->request->input('type',1);
        $uid = $this->request->input('uid',$this->uid());
        $result=(new User())->getFocus($uid,$type);
        return Response::success($result);

    }

    /**
     * @api {post} /user/feedback 意见反馈
     * @apiName UserInfoLocation
     * @apiGroup UserInfo
     * @apiDescription
     * @apiHeader {String} Authorization='Bearer '
     */
    public function feedback(){
        $data = $this->data(['content']);
        $data['user_id']=$this->uid();
        $result=UsersFeedback::create($data);
        return Response::success($result);

    }

    public function tlsSig(){
        $tls = new TLSSigAPIv2(1600005194,'af00c036c52c0983e970222ba20be84657b55e78d6f8c2d6fa1094f172b0e0f4');
        $sig = $tls->genUserSig($this->uid());
        return Response::success($sig);
    }

}
